#ifndef STX_ALGORITHM_REMOVE_IF_HPP
#define STX_ALGORITHM_REMOVE_IF_HPP

#include <stx/algorithm/common.hpp>
#include <stx/algorithm/find_if.hpp>

namespace stx {

template <class ForwardIterator, class Predicate>
ForwardIterator
remove_if(ForwardIterator first, ForwardIterator last, Predicate pred)
{
    first = stx::find_if<ForwardIterator, typename add_lvalue_reference<Predicate>::type>(first, last, pred);
    if (first != last) {
        ForwardIterator i = first;
        while (++i != last) {
            if (!pred(*i)) {
                *first = stx::move(*i);
                ++first;
            }
        }
    }
    return first;
}

} // namespace stx

#endif // STX_ALGORITHM_REMOVE_IF_HPP
